<?php
require_once("init.php");
/*
1, 表示雅虎
2, 表示GMAIL
3, 表示HOTMAIL
4, 表示testsend
5, 表示AOL
6, 表示VERIFY
*/
$sql = "select * from unsub where flag = 0 order by id asc";
$result = $GLOBALS['db']->dbfetchAll($sql);
foreach($result as $value){
	if($value['type']=='1'){
		$sql = "update yahoo set unsubscribe = 1 where id = ".$value['emailId']." and address='".$value['email']."'";
		$GLOBALS['db']->dbquery($sql);
	}else if($value['type']=='2'){
		$sql = "update gmail set unsubscribe = 1 where id = ".$value['emailId']." and address='".$value['email']."'";
		$GLOBALS['db']->dbquery($sql);	
	}else if($value['type']=='3'){
		$sql = "update hotmail set unsubscribe = 1 where id = ".$value['emailId']." and address='".$value['email']."'";
		$GLOBALS['db']->dbquery($sql);	
	}else if($value['type']=='4'){
		$sql = "update testsend set unsubscribe = 1 where id = ".$value['emailId']." and address='".$value['email']."'";
		$GLOBALS['db']->dbquery($sql);	
	}else if($value['type']=='5'){
		$sql = "update aol set unsubscribe = 1 where id = ".$value['emailId']." and address='".$value['email']."'";
		$GLOBALS['db']->dbquery($sql);	
	}else if($value['type']=='6'){
		$sql = "update verify set unsubscribe = 1 where id = ".$value['emailId']." and address='".$value['email']."'";
		$GLOBALS['db']->dbquery($sql);	
	}else{
		$sql = "update unsub set flag = 999 where id = ".$value['id']."";
		$GLOBALS['db']->dbquery($sql);	
	}
	$sql = "update unsub set flag = 1 where id = ".$value['id']."";
	$GLOBALS['db']->dbquery($sql);
}

foreach($result as $value){
	$sql = "delete form tempTemplate where address = '".$value['email']."'";
	$GLOBALS['db']->dbquery($sql);
}
foreach($result as $value){
	$sql = "delete form openStatistics where address = '".$value['email']."' and type = ".$value['type']." and addressId = ".$value['emailId']."";
	$GLOBALS['db']->dbquery($sql);
}
foreach($result as $value){
	$sql = "delete form clickTrack where address = '".$value['email']."' and addressId = ".$value['emailId']."";
	$GLOBALS['db']->dbquery($sql);
}
?>